package util;
import org.sql2o.Connection;
import org.sql2o.Sql2o;
import util.SQLS.doSomething;

public class DBConnector {
    public static Sql2o connector() {
        try {
            Class.forName("org.sqlite.JDBC");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        return new Sql2o("jdbc:sqlite:G:/Java/student-canteen-backend/db/backend.db",null,null);
    }

    public static <T>T result(doSomething<T> q) {
        Sql2o connector = connector();
        Connection transaction = connector.beginTransaction();
        try {
            transaction.commit();
           return q.query(transaction);
        } catch (Exception e) {
            transaction.rollback(false);
            throw new RuntimeException(e);
        }
    }


}
